package cn.vc.content.service.article;

import cn.vc.content.entity.article.ArticleCoins;
import cn.vc.content.mapper.article.ArticleCoinsMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ArticleCoinsService {
    @Autowired
    private ArticleCoinsMapper articleCoinsMapper;


    public boolean coins(Long id, Long userId, Long coins) {
        LambdaQueryWrapper<ArticleCoins> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ArticleCoins::getArticleId, id).eq(ArticleCoins::getUserId, userId);
        ArticleCoins articleCoins = articleCoinsMapper.selectOne(lqw);
        // 以及给该视频投过币，不可重复投币
        if (articleCoins != null) return false;
        articleCoins = new ArticleCoins();
        articleCoins.setArticleId(id);
        articleCoins.setUserId(userId);
        articleCoins.setCoins(coins.intValue());
        return articleCoinsMapper.insert(articleCoins)==1;
    }
}
